package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.ActivitiesDto;
import com.qk.entity.Activities;
import com.qk.mapper.ActivitiesMapper;
import com.qk.service.ActivitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivitiesServiceImpl implements ActivitiesService {
    @Autowired
    private ActivitiesMapper activitiesMapper;
    @Override
    public PageResult<Activities> list(ActivitiesDto activitiesDto) {
        PageHelper.startPage(activitiesDto.getPage(), activitiesDto.getPageSize());
        List<Activities> activities = activitiesMapper.selectList(activitiesDto);
        Page<Activities> lists =(Page<Activities>) activities;
        return new PageResult<>(lists.getTotal(),lists.getResult());
    }

    @Override
    public void delete(Integer id) {
        activitiesMapper.delete(id);
    }

    @Override
    public void add(Activities activities) {
        activities.setUpdateTime(LocalDateTime.now());
        activities.setCreateTime(LocalDateTime.now());
        activitiesMapper.add(activities);
    }

    @Override
    public Activities getById(Integer id) {
       Activities activities = activitiesMapper.getById(id);
        return activities;
    }

    @Override
    public void update(Activities activities) {
        activities.setUpdateTime(LocalDateTime.now());
        activitiesMapper.update(activities);
    }

    @Override
    public List<Activities> getByType(Integer type) {
        List<Activities> activities = activitiesMapper.getByType(type);
        return activities;
    }
}
